<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            display: flex;
        }
        /* 第一种： position + margin:auto  */
        .wrap{
            position: relative;
            width: 300px;
            height: 300px;
            border: 1px solid blue;
        }
        .inner{
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
        /* 第二种： position + 负margin */
        .wrap2{
            position: relative;
            width: 300px;
            height: 300px;
            border: 1px solid blue;
        }
        .inner2{
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -50px;
            margin-left: -50px;
            /* transform: translate(-50%, -50%); */
            width: 100px;
            height: 100px;
            background-color: skyblue;
        }

        /* 第三种： 单行文本水平垂直居中：line-height 和 height 等高 + text-align */
        .wrap3{
            width: 300px;
            height: 300px;
            border: 1px solid blue;
            text-align: center;
        }
        .inner3{
            line-height: 300px;
            background-color: orange;
        }

        /* 第四种： flex */
        .wrap4{
            display: flex;
            justify-content: center;
            align-items: center;
            width: 300px;
            height: 300px;
            border: 1px solid blue;
        }
        .inner4{
            width: 100px;
            height: 100px;
            background-color: purple;
        }
        
    </style>
</head>
<body>
    <div class="wrap">
        <div class="inner"></div>
    </div>
    <div class="wrap2">
        <div class="inner2"></div>
    </div>
    <div class="wrap3">
        <!-- <div class="inner3"></div> -->
        <!-- <img class="inner3" src="" alt=""> -->
        <span class="inner3">123</span>
    </div>
    <div class="wrap4">
        <div class="inner4"></div>
    </div>
</body>
</html>